<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-center-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.3" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="32x32" href="http://7xqdz8.com1.z0.glb.clouddn.com/avatar.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="16x16" href="http://7xqdz8.com1.z0.glb.clouddn.com/avatar.png?v=5.1.3">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.3" color="#222">





  <meta name="keywords" content="Java,笔记," />










<meta name="description" content="Xml与Html的区别尽管Xml与Html都是标准通用标记语言(SGML)的衍生语言，但还是存在不少区别:

Xml对大小写很敏感，例如&amp;lt;H1&amp;gt;与&amp;lt;h1&amp;gt;是不同的Xml标签
Html在能够分清段落结尾时候结束标签(&amp;lt;/p&amp;gt;或&amp;lt;/li&amp;gt;)可以省略，但是Xml中绝对不可以省略标签
在Xml中，属性值的引号是必须要有的，但Html中是可有可无的，如widt">
<meta property="og:type" content="article">
<meta property="og:title" content="Xml与Java">
<meta property="og:url" content="/2016/01/27/xml/index.html">
<meta property="og:site_name" content="一路前行">
<meta property="og:description" content="Xml与Html的区别尽管Xml与Html都是标准通用标记语言(SGML)的衍生语言，但还是存在不少区别:

Xml对大小写很敏感，例如&amp;lt;H1&amp;gt;与&amp;lt;h1&amp;gt;是不同的Xml标签
Html在能够分清段落结尾时候结束标签(&amp;lt;/p&amp;gt;或&amp;lt;/li&amp;gt;)可以省略，但是Xml中绝对不可以省略标签
在Xml中，属性值的引号是必须要有的，但Html中是可有可无的，如widt">
<meta property="og:updated_time" content="2016-01-27T03:59:45.654Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Xml与Java">
<meta name="twitter:description" content="Xml与Html的区别尽管Xml与Html都是标准通用标记语言(SGML)的衍生语言，但还是存在不少区别:

Xml对大小写很敏感，例如&amp;lt;H1&amp;gt;与&amp;lt;h1&amp;gt;是不同的Xml标签
Html在能够分清段落结尾时候结束标签(&amp;lt;/p&amp;gt;或&amp;lt;/li&amp;gt;)可以省略，但是Xml中绝对不可以省略标签
在Xml中，属性值的引号是必须要有的，但Html中是可有可无的，如widt">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '5.1.3',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="/2016/01/27/xml/"/>





  <title>Xml与Java | 一路前行</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?8193f7e44c62cdda245d5f109196c830";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">一路前行</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">Always believe that some thing wonderful is about to happen.</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="/2016/01/27/xml/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Voyager">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="http://7xqdz8.com1.z0.glb.clouddn.com/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一路前行">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Xml与Java</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2016-01-27T11:00:00+08:00">
                2016-01-27
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Java核心技术笔记/" itemprop="url" rel="index">
                    <span itemprop="name">Java核心技术笔记</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="Xml_u4E0EHtml_u7684_u533A_u522B"><a href="#Xml_u4E0EHtml_u7684_u533A_u522B" class="headerlink" title="Xml与Html的区别"></a>Xml与Html的区别</h1><p>尽管Xml与Html都是标准通用标记语言(SGML)的衍生语言，但还是存在不少区别:</p>
<ul>
<li>Xml对<strong>大小写很敏感</strong>，例如<code>&lt;H1&gt;</code>与<code>&lt;h1&gt;</code>是不同的Xml标签</li>
<li>Html在能够分清段落结尾时候结束标签(<code>&lt;/p&gt;</code>或<code>&lt;/li&gt;</code>)可以省略，但是Xml中绝对不可以省略标签</li>
<li>在Xml中，属性值的<strong>引号是必须要有的</strong>，但Html中是可有可无的，如<code>width=300</code></li>
<li>在Xml中，只有单个标签而没有相对应的结束标签的元素<strong>必须以<code>/</code>结尾</strong>，如<code>&lt;img src=&quot;test.png&quot; /&gt;</code></li>
<li>在Html中，属性可以只有名字没有值，在Xml中这是不允许的</li>
</ul>
<h1 id="Xml_u6587_u6863_u89C4_u8303"><a href="#Xml_u6587_u6863_u89C4_u8303" class="headerlink" title="Xml文档规范"></a>Xml文档规范</h1><ul>
<li>最好加上文档头 <code>&lt;?xml version=1.0?&gt;</code></li>
<li><p>避免使用混合式内容: </p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!--以下做法不推荐使用--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="title">font</span>&gt;</span></span><br><span class="line">   Helvetica</span><br><span class="line">   <span class="tag">&lt;<span class="title">size</span>&gt;</span>36<span class="tag">&lt;/<span class="title">size</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="title">font</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>属性只应该用来对修改值的描述，而不是用来指定值</p>
</li>
</ul>
<h1 id="u89E3_u6790Xml_u6587_u6863"><a href="#u89E3_u6790Xml_u6587_u6863" class="headerlink" title="解析Xml文档"></a>解析Xml文档</h1><p>Java提供了两种Xml解析器</p>
<ul>
<li>像文档对象模型(Document Object Model, DOM)解析器这样的叫树型解析器，它们将读入的Xml文档转换成树结构</li>
<li>像Xml简单Api(Simple API for Xml, SAX)解析器这样的流机制解析器，它们在读入Xml文档时生成相应的事件</li>
</ul>
<blockquote>
<ol>
<li>DOM解析器对于实现大多数目的来说都更容易一些。但如果要处理很长的文档，用它生成树结构将会消耗大量内存，或者如果只是对于某些元素感兴趣，而不关心它们的上下文，那么在这些情况下应该考虑使用流机制解析器。</li>
<li>对于获取到的数据通常 <code>trim()</code>一下</li>
</ol>
</blockquote>
<h2 id="u5F85_u7EED"><a href="#u5F85_u7EED" class="headerlink" title="待续"></a><strong><em>待续</em></strong></h2>
      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div></div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="http://7xqdz8.com1.z0.glb.clouddn.com/pay_weixin.png" alt="Voyager 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="http://7xqdz8.com1.z0.glb.clouddn.com/pay_alipay.jpg" alt="Voyager 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Java/" rel="tag"># Java</a>
          
            <a href="/tags/笔记/" rel="tag"># 笔记</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/01/26/Snackbar/" rel="next" title="弹出消息的新方式——Snackbar">
                <i class="fa fa-chevron-left"></i> 弹出消息的新方式——Snackbar
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/01/29/tab/" rel="prev" title="使用Tab创建滑动视图">
                使用Tab创建滑动视图 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="http://7xqdz8.com1.z0.glb.clouddn.com/avatar.png"
                alt="Voyager" />
            
              <p class="site-author-name" itemprop="name">Voyager</p>
              <p class="site-description motion-element" itemprop="description">Android Developer</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">41</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                
                  <span class="site-state-item-count">10</span>
                  <span class="site-state-item-name">标签</span>
                
              </div>
            

          </nav>

          

          <div class="links-of-author motion-element">
            
              
                <span class="links-of-author-item">
                  <a href="https://github.com/a-voyager" target="_blank" title="GitHub">
                    
                      <i class="fa fa-fw fa-github"></i>GitHub</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="mailto:w19961009@126.com" target="_blank" title="E-Mail">
                    
                      <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="https://weibo.com/u/2306071720" target="_blank" title="微博">
                    
                      <i class="fa fa-fw fa-weibo"></i>微博</a>
                </span>
              
            
          </div>

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Xml_u4E0EHtml_u7684_u533A_u522B"><span class="nav-number">1.</span> <span class="nav-text">Xml与Html的区别</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Xml_u6587_u6863_u89C4_u8303"><span class="nav-number">2.</span> <span class="nav-text">Xml文档规范</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#u89E3_u6790Xml_u6587_u6863"><span class="nav-number">3.</span> <span class="nav-text">解析Xml文档</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#u5F85_u7EED"><span class="nav-number">3.1.</span> <span class="nav-text">待续</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2015 &mdash; <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">WuHaojie</span>

  
</div>









        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>

  
  <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.3"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.3"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.3"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.3"></script>



  


  




	





  





  








  





  

  

  

  

  

  

</body>
</html>
